//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2021 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto/tree/main/CodeGenerator. DO NOT EDIT.

import SotoCore

/// Error enum for SimpleDB
public struct SimpleDBErrorType: AWSErrorType {
    enum Code: String {
        case attributeDoesNotExist = "AttributeDoesNotExist"
        case duplicateItemName = "DuplicateItemName"
        case invalidNextToken = "InvalidNextToken"
        case invalidNumberPredicates = "InvalidNumberPredicates"
        case invalidNumberValueTests = "InvalidNumberValueTests"
        case invalidParameterValue = "InvalidParameterValue"
        case invalidQueryExpression = "InvalidQueryExpression"
        case missingParameter = "MissingParameter"
        case noSuchDomain = "NoSuchDomain"
        case numberDomainAttributesExceeded = "NumberDomainAttributesExceeded"
        case numberDomainBytesExceeded = "NumberDomainBytesExceeded"
        case numberDomainsExceeded = "NumberDomainsExceeded"
        case numberItemAttributesExceeded = "NumberItemAttributesExceeded"
        case numberSubmittedAttributesExceeded = "NumberSubmittedAttributesExceeded"
        case numberSubmittedItemsExceeded = "NumberSubmittedItemsExceeded"
        case requestTimeout = "RequestTimeout"
        case tooManyRequestedAttributes = "TooManyRequestedAttributes"
    }

    private let error: Code
    public let context: AWSErrorContext?

    /// initialize SimpleDB
    public init?(errorCode: String, context: AWSErrorContext) {
        guard let error = Code(rawValue: errorCode) else { return nil }
        self.error = error
        self.context = context
    }

    internal init(_ error: Code) {
        self.error = error
        self.context = nil
    }

    /// return error code string
    public var errorCode: String { self.error.rawValue }

    /// The specified attribute does not exist.
    public static var attributeDoesNotExist: Self { .init(.attributeDoesNotExist) }
    /// The item name was specified more than once.
    public static var duplicateItemName: Self { .init(.duplicateItemName) }
    /// The specified NextToken is not valid.
    public static var invalidNextToken: Self { .init(.invalidNextToken) }
    /// Too many predicates exist in the query expression.
    public static var invalidNumberPredicates: Self { .init(.invalidNumberPredicates) }
    /// Too many predicates exist in the query expression.
    public static var invalidNumberValueTests: Self { .init(.invalidNumberValueTests) }
    /// The value for a parameter is invalid.
    public static var invalidParameterValue: Self { .init(.invalidParameterValue) }
    /// The specified query expression syntax is not valid.
    public static var invalidQueryExpression: Self { .init(.invalidQueryExpression) }
    /// The request must contain the specified missing parameter.
    public static var missingParameter: Self { .init(.missingParameter) }
    /// The specified domain does not exist.
    public static var noSuchDomain: Self { .init(.noSuchDomain) }
    /// Too many attributes in this domain.
    public static var numberDomainAttributesExceeded: Self { .init(.numberDomainAttributesExceeded) }
    /// Too many bytes in this domain.
    public static var numberDomainBytesExceeded: Self { .init(.numberDomainBytesExceeded) }
    /// Too many domains exist per this account.
    public static var numberDomainsExceeded: Self { .init(.numberDomainsExceeded) }
    /// Too many attributes in this item.
    public static var numberItemAttributesExceeded: Self { .init(.numberItemAttributesExceeded) }
    /// Too many attributes exist in a single call.
    public static var numberSubmittedAttributesExceeded: Self { .init(.numberSubmittedAttributesExceeded) }
    /// Too many items exist in a single call.
    public static var numberSubmittedItemsExceeded: Self { .init(.numberSubmittedItemsExceeded) }
    /// A timeout occurred when attempting to query the specified domain with specified query expression.
    public static var requestTimeout: Self { .init(.requestTimeout) }
    /// Too many attributes requested.
    public static var tooManyRequestedAttributes: Self { .init(.tooManyRequestedAttributes) }
}

extension SimpleDBErrorType: Equatable {
    public static func == (lhs: SimpleDBErrorType, rhs: SimpleDBErrorType) -> Bool {
        lhs.error == rhs.error
    }
}

extension SimpleDBErrorType: CustomStringConvertible {
    public var description: String {
        return "\(self.error.rawValue): \(self.message ?? "")"
    }
}
